package com.fxd.crm.service.impl.CourseOrderBaseImpl;

import com.fxd.crm.mapper.CourseOrderBaseMapper;
import com.fxd.crm.mapper.CourseOrderMapper;
import com.fxd.crm.model.CourseOrder;
import com.fxd.crm.model.PageResult;
import com.fxd.crm.service.ICourseOrderBaseService;
import com.fxd.crm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther fuxudong
 * @date 2021/3/28 - 18:08
 */
@Service
public class CourseOrderBaseImpl implements ICourseOrderBaseService {

    @Autowired
    CourseOrderBaseMapper orderBaseMapper;


    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder courseOrder, int Page, int PageSize) {
        System.out.println();
        PageResult<CourseOrder> result = new PageResult<>();
        result.setCode(0);
        Map<String, Object> params = new HashMap<>();
        params.put("condition",courseOrder);
        params.put("start",(Page-1)*PageSize);
        params.put("pageSize",PageSize);
        int count = orderBaseMapper.findCountByMap(params);
        result.setCount(count);
        //获取查询的数据
        List<CourseOrder> list = orderBaseMapper.findListByMap(params);
        result.setData(list);
        return result;
    }

    @Override
    public PageResult<CourseOrder> findPageResultByName(String name, int Page, int PageSize) {
        PageResult<CourseOrder> result = new PageResult<>();
        result.setCode(0);
        int count = orderBaseMapper.findCountByMapByName(name);
        result.setCount(count);
        //获取查询的数据
        List<CourseOrder> list = orderBaseMapper.findListByMapByName(name);
        result.setData(list);
        return result;
    }

    @Override
    public void save(CourseOrder courseOrder) {
        orderBaseMapper.insert(courseOrder);
    }

    @Override
    public CourseOrder findByOrderId(Integer order_id) {
        CourseOrder courseOrder = orderBaseMapper.findByOrderId(order_id);
        return courseOrder;
    }

    @Override
    public void deleteByOrderId(Integer order_id) {
        orderBaseMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(CourseOrder order) {
        orderBaseMapper.update(order);
    }
}
